<!---

CF_Kalendar

COPYRIGHT & LICENSING INFO
-------------------------------------------------------------------

Copyright 2006 TJ Downes - tdownes@sanative.net - http://www.sanative.net

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.

--->
<cfcomponent displayname="Application" hint="The Application.cfc" output="yes">

	<cfset this.name = "KalendarAdmin-1.0RC5" />
	<cfset this.sessionmanagement = true />
	<cfset this.loginstorage="session">
	<cfset this.sessiontimeout = CreateTimeSpan(0,0,30,0) />
	
 	<cffunction name="onError">

		<cfargument name="Exception" required="true" />
			
		<cfargument type="String" name="EventName" required="true" />
		
		<cfif StructKeyExists(application, KConfig) AND application.KConfig.getCurrentMode() IS 'Development' >
			<cfdump var="#arguments#">

		<cfelse>
			<!--- Display an error message if there is a page context. --->
			<cfif isDefined("arguments.exception.rootCause")>
				<cfif arguments.exception.rootCause eq "coldfusion.runtime.AbortException">
					<cfreturn/>
				</cfif>
			</cfif>
			<cfif NOT (Arguments.EventName is "onSessionEnd") OR (Arguments.EventName is "onApplicationEnd")>
				Error!
				<cfmail to="email@domain" from="kalendar@sanative.net" subject="Kalendar Admin Error" type="html"><cfdump var="#Arguments#" /></cfmail>
				<cfabort />
			</cfif>
		</cfif>
	</cffunction> 
	
	<cffunction name="onApplicationStart">
		
		<cfscript>
			//create the configuration object for this instance of Kalendar
			//Important!  Put the complete path from your coldfusion root here: ( note: do not end with CFC.   e.g. ( 'Kalendar.common.cfc.KalendarConfig' )
			var PathToKalendarConfig = "Kalendar.common.cfc.KalendarConfig";
			var KConfig = createobject("component", PathToKalendarConfig ).init();
			//Run the configuration manager
			KConfig.configure();
			//All done, lets put this somewhere accessible
			application.KConfig = KConfig;
		</cfscript>

	</cffunction>
	
	<cffunction name="onSessionStart" access="public" returntype="void" output="false">
	</cffunction>
	
	<cffunction name="onSessionEnd" access="public" returntype="void" output="false">
	</cffunction>
	
	<cffunction name="onRequestStart">
		
		<cfif structKeyExists( url, application.KConfig.getReloadKey() ) >
			<cfif url[application.KConfig.getReloadKey()] IS application.KConfig.getReloadPassword() >
				<cfset structClear( application ) />
				<cfset structClear( session ) />
				<cfset onApplicationStart() />
			</cfif>
		</cfif>		
		
	</cffunction>

	<cffunction name="onRequestEnd">
		<cfif StructKeyExists(request, "relocate")>
			<script>window.location = '<cfoutput>#request.relocate#</cfoutput>';</script>
		</cfif>
		<cfif isDefined("returnMessage")>
			<script>alert("<cfoutput>#returnMessage#</cfoutput>")</script>	
		</cfif>
	</cffunction>

</cfcomponent>